var storage = window.localStorage;
var deployId = storage["deployId"];
storage.clear();
var vm = new Vue({
    el: '#check',
    data: {
        deployId: {

        },
        activitiInfo:{

        },
        formdata:{

        },
        showData: false,
        arrenum:{},
        enumdata:{

        }

    },
    methods: {
        //获取检查单填写数据
        getDeployInfo: function () {
            vm.showData = true;
            var url = "/workflow/actFlow/findProcessForm?processDefinitionId="+deployId;
            $.ajax({
                type: "GET",
                url: baseURL + url,
                contentType: "application/json",
                success: function (r) {
                    console.info(r);
                    if (r.code == 0) {
                        vm.activitiInfo = r.data.form;
                        vm.enumdata=r.data;
                        vm.activitiInfo.formProperties.forEach(function(val,index,arr){
                           if(val.type.name=='enum') {
                                 var datajson= 'enum_'+ val.id;
                                 var data=vm.enumdata[datajson];
                                var myArray=new Array();
                                var i=0;
                               for(var name in data){//遍历对象属性名
                                   var  obj={};
                                   obj.name=name;
                                   obj.value=data[name];
                                   myArray[i]=obj;
                                   i++;
                               }
                               val.list=myArray;
                           }
                        });
                    } else {
                        alert(r.errorMessage);
                    }
                }
            });
        },

        startworkflow: function () {
            vm.showData = true;

            vm.activitiInfo.formProperties.forEach(function(val,index,arr){
                vm.formdata[val.name]= $('#'+val.name).val();
            });
            vm.formdata["processDefinitionId"]=deployId;
          var url = "/workflow/actFlow/startProcessByForm";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/x-www-form-urlencoded",
                data:vm.formdata,
                success: function (r) {
                    console.info(r);
                    if (r.code == 0) {
                      alert('申请流程启动');
                    } else {
                        alert(r.errorMessage);
                    }
                }
            });
        },
        goBack: function () {
            window.location.href = "deploy.html";
        },
        showInfo: function (id, key) {
            //显示选项图片
            $("#" + id + "_" + key + "_img_show").show();
            //显示选项文字
            $("#" + id + "_" + key + "_text_show").show();
            //显示下级选项
            $("#" + id + "_" + key).show();
        }
    }
});
$(function () {
    vm.getDeployInfo();
});
Vue.component('lower-option', {
    template: '#lowerOption',
    props: {item: {}, option: {}}
})

function formatTime(now) {
    var date = new Date(now);
    var year = date.getFullYear();  // 获取完整的年份(4位,1970)
    var month = date.getMonth() + 1;  // 获取月份(0-11,0代表1月,用的时候记得加上1)
    var day = date.getDate();  // 获取日(1-31)
    date.getTime();  // 获取时间(从1970.1.1开始的毫秒数)
    var hour = date.getHours();  // 获取小时数(0-23)
    var minutes = date.getMinutes();  // 获取分钟数(0-59)
    var seconds = date.getSeconds();  // 获取秒数(0-59)
    return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
}

function formatDate(now) {
    var date = new Date(now);
    var year = date.getFullYear();  // 获取完整的年份(4位,1970)
    var month = date.getMonth() + 1;  // 获取月份(0-11,0代表1月,用的时候记得加上1)
    var day = date.getDate();  // 获取日(1-31)
    return year + "-" + month + "-" + day;
}